import Vue from 'vue';
import TransferView from './transfer.vue';
let TransferConstructor  = Vue.extend(TransferView);

let instance;

var Transfer = function(options,entercallback,canclecallback) {
    if (Vue.prototype.$isServer) return;
    options = options || {};

    instance = new TransferConstructor({
        data : options,
        methods : {
            close () {
                instance.$destroy();
                Transfer.close();
                if(typeof canclecallback === 'function'){
                    canclecallback();
                }
            },
            enter () {
                if(typeof entercallback === 'function'){
                    entercallback(this.groupSelect);
                }
                this.close();
            }
        }
    });
    instance.vm = instance.$mount();

    document.body.appendChild(instance.vm.$el);
    instance.vm.visible = true;
    instance.dom = instance.vm.$el;
    return instance.vm;
};


Transfer.close = function() {
    document.body.removeChild(instance.$el);
};


export default Transfer;